﻿@{
    ViewBag.Title = "Category";
    Layout = "~/Views/Shared/BE/_Admin_Layout.cshtml";
}
<article class="module width_3_quarter">
    <div id="CategoryTable"></div>
</article>

<script type="text/javascript">

    $(document).ready(function () {

        //Prepare jtable plugin
        $('#CategoryTable').jtable({
           //...
            selecting: true, //Enable selecting
            multiselect: true, //Allow multiple selecting
            selectingCheckboxes: true, //Show checkboxes on first column
            openChildAsAccordion: true,
            paging: true,
            pageSize: 10,
            defaultSorting: 'CategoryName DESC',
            sorting: true,
            title: 'Danh sách các chuyên mục',
            actions: {
                listAction: '@Url.Action("ListCategory")',
                deleteAction: '@Url.Action("DeleteCategory")',
                updateAction: '@Url.Action("UpdateCategory")',
                createAction: '@Url.Action("CreateCategory")',
            },
            fields: {
                CategoryID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                CategoryName: {
                    title: 'Tiêu đề',
                    width: '90%',
                    inputClass: 'validate[required,maxSize[50]]'
                },
                ArticleCount: {
                    title: 'Tổng số bài viết',
                    width: '15%',
                    edit: false,
                    create: false
                }
            },
            //Initialize validation logic when a form is created
            formCreated: function (event, data) {
                $(data.form[0]).submit(function () {
                    return false;
                });
                data.form.validationEngine();
            },
            //Validate form when it is being submitted
            formSubmitting: function (event, data) {
                return data.form.validationEngine('validate');
            },
            //Dispose validation logic when form is closed
            formClosed: function (event, data) {
                data.form.validationEngine('hide');
                data.form.validationEngine('detach');
            }
        });

        //Re-load records when user click 'load records' button.
        $('#LoadRecordsButton').click(function (e) {
            e.preventDefault();
            $('#CategoryTable').jtable('load', {
                keywords: $('#name').val(),
            });
        });

        //Load person list from server
        $('#CategoryTable').jtable('load');
        
        //
        //Delete selected students
        $('#DeleteAllButton').button().click(function () {
            var $selectedRows = $('#CategoryTable').jtable('selectedRows');
            $('#CategoryTable').jtable('deleteRows', $selectedRows);
        });
    });

</script>